package cn.base.web.auth.token;

import cn.rengy.auth.AuthenToken;
import cn.rengy.auth.TokenType;
import cn.rengy.auth.token.AbstractAuthenTokenCreator;
import cn.rengy.auth.token.JwtToken;
import cn.rengy.util.web.RequestUtil;
import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Component;

@Component
//@ConditionalOnClass(javax.servlet.http.HttpServletRequest.class) 网关也有本地token，所以都需要加载
public class LocalAuthenTokenCreator extends AbstractAuthenTokenCreator {


    public LocalAuthenTokenCreator() {
        super(TokenType.LOCAL);
    }

    protected AuthenToken createToken(String token, Object request){
        return new JwtToken(token, RequestUtil.getUserAgent(request),RequestUtil.getClientIp(request));
    }


    @Override
    protected String getAuthorization(Object request) {
        return RequestUtil.getHeader(request,HttpHeaders.AUTHORIZATION);
    }
}
